<template>
  <el-card class="summary-card" shadow="hover">
    <div class="content-top">
      <div class="content-top-left">
        <component :is="icon" :color="iconColor"></component>
        <span class="title">{{ title }}</span>
      </div>
      <div class="content-top-right">
        <span>周</span>
      </div>
    </div>
    <div class="content-bottom">
      <div class="content-bottom-left">
        <span>{{ total }}</span>
      </div>
      <div class="content-bottom-right">
        <el-tag round effect="dark" :color="color">{{
          (percent || 0) + "%"
        }}</el-tag>
        <el-icon>
          <Top v-if="percent > 0" color="#F56C6C" />
          <Bottom v-else-if="percent < 0" color="#67C23A"></Bottom>
          <Minus v-else color="#909399"></Minus>
        </el-icon>
      </div>
    </div>
  </el-card>
</template>
<script lang="ts" setup>
import { computed } from "vue";
import type { Component } from "vue";

const props = defineProps<{
  icon: Component;
  iconColor: string;
  title: string;
  total: number;
  percent: number;
}>();
const color = computed(() => {
  if (props.percent > 0) {
    return "#F56C6C";
  } else if (props.percent < 0) {
    return "#67C23A";
  } else {
    return "#909399";
  }
});
</script>
<style lang="less" scoped>
.el-card.summary-card {
  margin-bottom: 12px;
  border-color: transparent;
  :deep(.el-card__body) {
    padding: 16px 20px;
  }
  .content-top,
  .content-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .content-top {
    .content-top-left {
      display: flex;
      flex-direction: column;
      align-items: center;
      .title {
        margin-top: 6px;
        font-size: 14px;
      }
    }
    .content-top-right {
      font-size: 14px;
      color: #888;
      font-weight: lighter;
    }
  }
  .content-bottom {
    .content-bottom-left > span {
      display: inline-block;
      line-height: 48px;
      font-size: 30px;
      font-weight: 500;
    }
    .content-bottom-right {
      display: flex;
      align-items: center;
      .el-tag {
        margin-right: 6px;
        border-color: transparent;
      }
    }
  }
}
</style>
